/*
 * Copyright 2007 Stefan Arentz <stefan@arentz.nl>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import "NSMutableDataAppendNativeTypesAdditions.h"

@implementation NSMutableData (AppendNativeTypes)

- (void) appendChar: (char) v
{
   [self appendBytes: &v length: sizeof(unsigned char)];
}

- (void) appendUnsignedChar: (unsigned char) v
{
   [self appendBytes: &v length: sizeof(unsigned char)];
}

- (void) appendInt: (int) v
{
   [self appendBytes: &v length: sizeof(int)];
}

- (void) appendSwappedInt: (int) v
{
   int swapped = CFSwapInt32HostToBig(v);
   [self appendBytes: &swapped length: sizeof(int)];
}

- (void) appendUnsignedInt: (unsigned int) v
{
   [self appendBytes: &v length: sizeof(unsigned int)];
}

- (void) appendSwappedUnsignedInt: (unsigned int) v
{
   unsigned int swapped = CFSwapInt32HostToBig(v);
   [self appendBytes: &swapped length: sizeof(int)];
}

- (void) appendSwappedDouble: (double) v
{
   CFSwappedFloat64 swapped = CFConvertDoubleHostToSwapped(v);
   [self appendBytes: &swapped length: sizeof(CFSwappedFloat64)];
}

- (void) appendDouble: (double) v
{
   [self appendBytes: &v length: sizeof(double)];
}

- (void) appendFloat: (float) v
{
   [self appendBytes: &v length: sizeof(float)];
}

- (void) appendSwappedFloat: (float) v
{
   CFSwappedFloat32 swapped = CFConvertFloat32HostToSwapped(v);
   [self appendBytes: &swapped length: sizeof(CFSwappedFloat32)];
}

- (void) appendCode: (unsigned int) v
{
   [self appendUnsignedInt: v];
}

- (void) appendSwappedCode: (unsigned int) v
{
   [self appendSwappedUnsignedInt: v];
}

@end
